<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/5/4
  Time: 16:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.DB_Order" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <title>更新订单</title>
</head>
<body>
<h2>更新订单</h2>
<%
    if ("post".equalsIgnoreCase(request.getMethod())) {
        String oid = request.getParameter("oid");
        String uid = request.getParameter("uid");
        String aid = request.getParameter("aid");
        String payamount = request.getParameter("payamount");
        String state = request.getParameter("state");

        // 数据有效性检查
        if (oid == null || oid.trim().isEmpty() ||
                uid == null || uid.trim().isEmpty() ||
                aid == null || aid.trim().isEmpty() ||
                payamount == null || payamount.trim().isEmpty() ||
                state == null || state.trim().isEmpty()) {
            out.println("请填写完整的订单信息");
            return;
        }

        try {
            Integer.parseInt(oid); // 检查oid是否为有效的整数
            Double.parseDouble(payamount); // 检查payamount是否为有效的数值
            Integer.parseInt(state); // 检查state是否为有效的整数
        } catch (NumberFormatException e) {
            out.println("输入的数据格式不正确");
            return;
        }

        List<String> updateInput = new ArrayList<>();
        updateInput.add(oid);
        updateInput.add(uid);
        updateInput.add(aid);
        updateInput.add(payamount);
        updateInput.add(state);

        DB_Order dbOrder = new DB_Order();
        boolean updateResult = dbOrder.update(updateInput);

        if (updateResult) {
            response.sendRedirect("index.jsp");
        } else {
            out.println("更新订单失败，请检查输入信息或联系管理员");
        }
    }
%>
</body>
</html>